<template>
	<view class="evaluate"> 
		<view class="evaluate_content">
			<view class="tabList_tab">
				<tutor-tab :list="['店铺评价','已处理评价']" @clickSwtichTab="clickSwtichTab"
					:atciveIndex="atciveIndex"></tutor-tab>
			</view>
			
			<view class="news_list">
				<z-paging :fixed="false" ref="paging" v-model="dataList" @query="queryList">
					<NewsItem v-if="!atciveIndex" isOperate :dataList="dataList" @delAppraise="delAppraise" @replyAppraise="toReplayAppraise"></NewsItem>
					<NewsItem v-else isNickameBottom isStore :dataList="dataList"></NewsItem>
				</z-paging>
			</view>
		</view>
	</view>
</template>

<script>
	import NewsItem from "./compontents/newsItem.vue"
	import { getTodolist,getProcessedList,deleteAppraise } from "@/http/api/appraise/appraise.js"  
	export default {
		components: {
			NewsItem
		},
		data() {
			return { 
				// tab切换
				atciveIndex: 0, //切换笔记和收藏列表
				dataList: [],
			}
		},
		props: {
			marginTp:{
				type: Number,
				default: 0
			},
			//oss
			ossUrl:{
				type: String,
				default:''
			}
		},
		computed:{
			merchantId(){
				return this.$store.state.userShopDetails.id
			}
		},
		methods: {  
			// tab切换
			clickSwtichTab(data) {
				this.atciveIndex = data.index
				this.$refs.paging.reload();
			},
			// 回复评论
			toReplayAppraise(e){
				uni.navigateTo({
					url:'/pages/appraiseControl/modules/replayAppraise/replayAppraise?id='+e.id
				})
			},
			// 删除评论
			delAppraise(e){
				deleteAppraise(e.id).then(res => {
					if (res.code == 200) {
						 this.$utils.toast("评论已删除");
						 this.$refs.paging.reload();
					} else {
						this.$utils.toast(res.msg);
					}
				}).catch(res => {
					this.$refs.paging.complete(false);
				})
			},
			// 数据分页
			queryList(pageNo, pageSize) {
				if(!this.atciveIndex){
					console.log({
						pageNum: pageNo,
						pageSize: pageSize,
						commentType: "2",
						beUserType: "1",
						beUserId: this.merchantId//this.merchantId
					})
					// 店铺评价列表数据
					getTodolist({
						pageNum: pageNo,
						pageSize: pageSize,
						commentType: "2",
						beUserType: "1",
						beUserId: this.merchantId//this.merchantId
					}).then(res => {
						console.log(res)
						if (res.code == 200) {
							 this.$refs.paging.complete(res.rows); 
						} else {
							this.$utils.toast(res.msg);
						}
					}).catch(res => {
						this.$refs.paging.complete(false);
					})
				}else{
					// 已处理评价列表数据
					getProcessedList({
						pageNum: pageNo,
						pageSize: pageSize,
						commentType: "2",
						beUserType: "1",
						beUserId: this.merchantId//this.merchantId
					}).then(res => {
						if (res.code == 200) {
							 this.$refs.paging.complete(res.rows); 
						} else {
							this.$utils.toast(res.msg);
						}
					}).catch(res => {
						this.$refs.paging.complete(false);
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.evaluate {
		.tui-header-icon {
			width: 100%;
			position: fixed;
			top: 0;
			padding: 0 0 0 38rpx;
			display: flex;
			align-items: center;
			height: 32px;
			transform: translateZ(0);
			box-sizing: border-box;
		}

		.evaluate_content {
			background-color: #f5f5f5;
			height: 88vh;
			width: 90vw;
			margin: 0 auto;
			padding-top: 45rpx;

			/* tab列表 */
			.tabList_tab {
				height: 148rpx;
			}

			// 消息列表
			.news_list {
				z-index: 9999;
				position: relative;
				background: #fff;
				height: 65vh;
				border-radius: 30rpx;
				padding: 0 40rpx;
				border: 1px solid #f5f5f5;
			}
		}
	}
</style>